/*
 * \brief  Server-side de-marshaller of I/O-port session interface
 * \author Christian Helmuth
 * \date   2007-04-17
 */

/*
 * Copyright (C) 2007-2009 Christian Helmuth
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

#ifndef _INCLUDE__IO_PORT_SESSION__SERVER_H_
#define _INCLUDE__IO_PORT_SESSION__SERVER_H_

#include <base/server.h>
#include <base/printf.h>
#include <io_port_session/io_port_session.h>

namespace Genode {

	class Io_port_session_server : public Server_object, public Io_port_session
	{
		public:

			int dispatch(int op, Ipc_istream &is, Ipc_ostream &os)
			{
				switch (op) {

				case INB:
					{
						unsigned short address = 0;

						is >> address;
						os << inb(address);

						return 0;
					}

				case INW:
					{
						unsigned short address = 0;

						is >> address;
						os << inw(address);

						return 0;
					}

				case INL:
					{
						unsigned short address = 0;

						is >> address;
						os << inl(address);

						return 0;
					}

				case OUTB:
					{
						unsigned short address = 0;
						unsigned char value = 0;

						is >> address >> value;
						outb(address, value);

						return 0;
					}

				case OUTW:
					{
						unsigned short address = 0;
						unsigned short value = 0;

						is >> address >> value;
						outw(address, value);

						return 0;
					}

				case OUTL:
					{
						unsigned short address = 0;
						unsigned value = 0;

						is >> address >> value;
						outl(address, value);

						return 0;
					}

				default:
					PWRN("unknown opcode %d", op);
					return -1;
				}
			}
	};
}

#endif /* _INCLUDE__IO_PORT_SESSION__SERVER_H_ */
